#ifndef STACK_SQ_H
#define STACK_SQ_H

#include <iostream>
#include <stdexcept>

using namespace std;

template<typename T>

class Stack_sq
{
private:
    T *data;
    int capacity;
    int size;
    void resize();
public:
    Stack_sq():data(new T[10]),size(0),capacity(10){};
    ~Stack_sq(){delete [] data;};
    void push(T element);
    T pop();
    T top() const;
    int getsize() const;
};

template<typename T>
void Stack_sq<T>::resize()
{
    int newcapacity = capacity*2;
    T *newdata = new T[newcapacity];
    for (int i = 0;i<size;i++)
    {
        newdata[i] = data[i];
    }
    delete[] data;
    data = newdata;
    capacity = newcapacity;
}

template<typename T>
void Stack_sq<T>::push(T element)
{
    if( size == capacity)
    {
        resize();
    }
    data[size++] = element;
}

template<typename T>
T Stack_sq<T>::pop()
{
    if (size == 0)
    {
        throw std::underflow_error("stack is empty");
    }
    return data[size--];
}

template<typename T>
T Stack_sq<T>::top() const
{
    if (size == 0)
    {
        throw std::underflow_error("stack is empty");
    }
    data[0] = 4;
    return data[size-1];
}

template<typename T>
int Stack_sq<T>::getsize() const
{
    return size;
}


#endif